/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.registration.business.security.entity;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlTransient;
import org.eclipse.persistence.annotations.Mutable;

/**
 *
 * @author Stefano
 */
@Entity
@Table(name = "EVENT")
public class Event implements Serializable {
    @Id
    private String id;

    @NotNull(message = "May not be empty")
    @Basic(optional = false)    
    private String title;

    @NotNull(message = "May not be empty")
    @Basic(optional = false)
    @Temporal(TemporalType.TIMESTAMP)
    @Mutable(true)
    private Calendar startTime;
    
    @NotNull(message = "May not be empty")
    @Basic(optional = false)
    @Temporal(TemporalType.TIMESTAMP)
    @Mutable(true)
    private Calendar endTime;
    
    @NotNull(message = "May not be empty")
    @Basic(optional = false)
    private String location;
    
    @NotNull(message = "May not be empty")
    @Basic(optional = false)
    private boolean outdoor; //1: outdoor, 0: indoor
    
    @NotNull(message = "May not be empty")
    @Basic(optional = false)
    private boolean visibility; //0: private, 1: public
    
    private String type;
    
    private String url;
    
    private String file;
    
    private String photo;
    
    private String notes;
    
    private Integer cadence;
    
    @Basic(optional = false)
    private int weatherCondition;
    
    @JoinColumn(referencedColumnName = "email")
    @ManyToOne(optional = false)
    private User creator;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
    private Collection<Invite> inviteCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
    private Collection<SystemNotification> systemNotificationCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
    private Collection<Personalize> personalizeCollection;
    
    public Event() {
    }

    public Event(String id) {
        this.id = id;
    }

    public Event(String id, String title, Calendar startTime, Calendar endTime, String location, boolean outdoor, boolean visibility, int weatherCondition) {
        this.id = id;
        this.title = title;
        this.startTime = startTime;
        this.endTime = endTime;
        this.location = location;
        this.outdoor = outdoor;
        this.visibility = visibility;
        this.weatherCondition = weatherCondition;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Calendar getStartTime() {
        return startTime;
    }

    public void setStartTime(Calendar startTime) {
        this.startTime = startTime;
    }

    public Calendar getEndTime() {
        return endTime;
    }

    public void setEndTime(Calendar endTime) {
        this.endTime = endTime;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public boolean getOutdoor() {
        return outdoor;
    }

    public void setOutdoor(boolean outdoor) {
        this.outdoor = outdoor;
    }

    public boolean getVisibility() {
        return visibility;
    }

    public void setVisibility(boolean visibility) {
        this.visibility = visibility;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getFile() {
        return file;
    }

    public void setFile(String file) {
        this.file = file;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public Integer getCadence() {
        return cadence;
    }

    public void setCadence(Integer cadence) {
        this.cadence = cadence;
    }

    public int getWeatherCondition() {
        return weatherCondition;
    }

    public void setWeatherCondition(int weatherCondition) {
        this.weatherCondition = weatherCondition;
    }

    public User getCreator() {
        return creator;
    }

    public void setCreator(User creator) {
        this.creator = creator;
    }
    
    @XmlTransient
    public Collection<Invite> getInviteCollection() {
        return inviteCollection;
    }

    public void setInviteCollection(Collection<Invite> inviteCollection) {
        this.inviteCollection = inviteCollection;
    }
    
    @XmlTransient
    public Collection<Personalize> getPersonalizeCollection() {
        return personalizeCollection;
    }

    public void setPersonalizeCollection(Collection<Personalize> personalizeCollection) {
        this.personalizeCollection = personalizeCollection;
    }
    
    @XmlTransient
    public Collection<SystemNotification> getSystemNotificationCollection() {
        return systemNotificationCollection;
    }

    public void setSystemNotificationCollection(Collection<SystemNotification> systemNotificationCollection) {
        this.systemNotificationCollection = systemNotificationCollection;
    }
    

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Event)) {
            return false;
        }
        Event other = (Event) object;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.registration.business.security.entity.Event[ id=" + id + " ]";
    }
    
}
